Attribute VB_Name = "Module1"
Option Explicit

'' Maximun long filename path length
''
Public Const MAX_PATH = 260


'' An item identifier is defined by the variable-length ItemID structure.
'' The first two bytes of this structure specify its size, and the format of
'' the remaining bytes depends on the parent folder
'' Except for the first two bytes, item identifiers are not strictly defined
''
Type ItemID
    cb As Long                                    ' Size of the ID (including cb itself)
    abID() As Byte                                ' The item ID (variable length)
End Type

'' The ITEMIDLIST structure defines an element in an item identifier list
'' (the only member of this structure is a ItemID structure). An item
'' identifier list consists of one or more consecutive ITEMIDLIST structures
'' packed on byte boundaries, followed by a 16-bit zero value.
''
Type ITEMIDLIST
    mkid As ItemID
End Type

'' Converts an item identifier list to a file system path.
'' Returns TRUE if successful or FALSE if an error occurs, for example,
'' if the location specified by the pidl parameter is not part of the file system.
''
Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" _
    (ByVal pIdl As Long, ByVal pszPath As String) As Long

    '' Retrieves the location of a special (system) folder.
    '' Returns NOERROR if successful or an OLE-defined error result otherwise.
    ''
Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" _
    (ByVal hwndOwner As Long, ByVal nFolder As Long, _
    pIdl As ITEMIDLIST) As Long

    '' SHGetSpecialFolderLocation successful rtn val
Public Const NOERROR = 0

'' Frees memory allocated by SHBrowseForFolder()
Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long)

'' Displays a dialog box that enables the user to select a shell folder.
'' Returns a pointer to an item identifier list that specifies the location
'' of the selected folder relative to the root of the name space. If the user
'' chooses the Cancel button in the dialog box, the return value is NULL.
''
Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long

'' BROWSEINFO ulFlags values:
'' Value specifying the types of folders to be listed in the dialog box as well as
'' other options. This member can include zero or more of the following values:
''
'' Only returns file system directories. If the user selects folders
'' that are not part of the file system, the OK button is grayed.
Public Const BIF_RETURNONLYFSDIRS = &H1

'' Only returns file system ancestors. If the user selects anything other
'' than a file system ancestor, the OK button is grayed.
Public Const BIF_RETURNFSANCESTORS = &H8

'' Does not include network folders below the domain level in the tree view control.
'' For starting the Find Computer
Public Const BIF_DONTGOBELOWDOMAIN = &H2

'' Only returns computers. If the user selects anything other
'' than a computer, the OK button is grayed.
''
Public Const BIF_BROWSEFORCOMPUTER = &H1000

'' Contains parameters for the the SHBrowseForFolder function and receives
'' information about the folder selected by the user.
Public Type BROWSEINFO
''
'' Handle of the owner window for the dialog box.
    hOwner As Long
    
    '' Pointer to an item identifier list (an ITEMIDLIST structure) specifying the location
    '' of the "root" folder to browse from. Only the specified folder and its subfolders
    '' appear in the dialog box. This member can be NULL, and in that case, the
    '' name space root (the desktop folder) is used.
    pidlRoot As Long
    
    '' Pointer to a buffer that receives the display name of the folder selected by the
    '' user. The size of this buffer is assumed to be MAX_PATH bytes.
    pszDisplayName As String
    
    '' Pointer to a null-terminated string that is displayed above the tree view control
    '' in the dialog box. This string can be used to specify instructions to the user.
    lpszTitle As String
    
    '' Value specifying the types of folders to be listed in the dialog box as well as
    '' other options. This member can include zero or more of the following values below.
    ulFlags As Long
    
    '' Address an application-defined function that the dialog box calls when events
    '' occur. For more information, see the description of the BrowseCallbackProc
    '' function. This member can be NULL.
    lpfn As Long
    
    '' Application-defined value that the dialog box passes to the callback function
    '' (if one is specified).
    lParam As Long
    
    '' Variable that receives the image associated with the selected folder. The image
    '' is specified as an index to the system image list.
    iImage As Long
End Type



